package com.ag.zrt.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ag.bean.TbEventLevel;
import com.ag.common.AgException;
import com.ag.common.IDUtil;
import com.ag.common.IIDService;
import com.ag.zrt.dao.TbEventLevelDAO;
import com.ag.zrt.service.EventLevelService;

@Service("EventLevelService")
public class EventLevelServiceImpl implements EventLevelService {
    @Resource(name="ZRTTbEventLevelDAO")
	private TbEventLevelDAO tbEventLevelDAO;
	@Resource(name="iDServiceImpl")
	private IIDService idService;

	// private TbEventLevel eventLevel;

	public void save(TbEventLevel el) throws Exception {
		String elId = idService.findTablePK(IDUtil.TB_EVENT_LEVEL);
		el.setElId(elId);
		el.setA(IDUtil.PRESERVE);
		tbEventLevelDAO.save(el);
	}

	public void setTbEventLevelDAO(TbEventLevelDAO tbEventLevelDAO) {
		this.tbEventLevelDAO = tbEventLevelDAO;
	}

	public List<TbEventLevel> findAll() {
		StringBuilder sb = new StringBuilder();
		sb.append("from TbEventLevel el where el.a = "+IDUtil.PRESERVE);
		return tbEventLevelDAO.find(sb.toString());
	}

	public void update(TbEventLevel eventLevel) {
		// TODO Auto-generated method stub
		eventLevel.setA(IDUtil.PRESERVE);
		tbEventLevelDAO.attachDirty(eventLevel);

	}

	public void delete(TbEventLevel el) {
		// TODO Auto-generated method stub
		TbEventLevel tel = tbEventLevelDAO.findById(el.getElId());
		tel.setA(IDUtil.DELETE);
		tbEventLevelDAO.attachDirty(tel);
	}

	public TbEventLevel findById(String id) {
		// TODO Auto-generated method stub
		return tbEventLevelDAO.findById(id);
	}
}
